﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;

namespace Microsoft.Samples.DslTools.ConfigurationSectionDesigner
{
    public class AttributeList : LinkedList<Attribute>
    {
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if( this.Count > 0 )
            {
                foreach( Attribute attribute in this )
                    sb.AppendFormat( "{0}, ", attribute.ToString() );
                sb.Remove( sb.Length - 2, 2 );
            }
            return sb.ToString();
        }
    }

    public class Attribute
    {
        public string Name { get; set; }
        public LinkedList<AttributeParameter> Parameters { get; private set; }

        public Attribute()
        {
            Parameters = new LinkedList<AttributeParameter>();
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append( "[" );
            sb.Append( Name );
            if( Parameters.Count > 0 )
            {
                sb.Append( "(" );
                foreach( AttributeParameter parameter in Parameters )
                    sb.AppendFormat( "{0}, ", parameter.ToString() );
                sb.Remove( sb.Length - 2, 2 );
                sb.Append( ")" );
            }
            sb.Append( "]" );

            return sb.ToString();
        }
    }

    public class AttributeParameter
    {
        public string Name { get; set; }
        public string Value { get; set; }

        public override string ToString()
        {
            if( !string.IsNullOrEmpty( Name ) )
                return string.Format( "{0} = {1}", Name, Value );
            else
                return Value;
        }
    }
}
